package com.example.jetpackcomposestate.examples

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import com.example.jetpackcomposestate.ui.theme.JetpackComposeBasicTheme

/**
 * @author huangzehui
 * @date 8/5/2024 下午10:36 周三
 * @description
 *
 * https://www.bilibili.com/video/BV1ob4y1a7ad?p=51&spm_id_from=pageDriver&vd_source=e07cc8cc94eb22bd76722071b03cd199
 */
class AnnotatedStringActivity : ComponentActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            JetpackComposeBasicTheme {
                helloAnnotatedString()
            }
        }
    }


    @Composable
    fun helloAnnotatedString() {

        val tagStyle = MaterialTheme.typography.headlineMedium.toSpanStyle().copy(
            background = MaterialTheme.colorScheme.primary.copy(alpha = 0.1f)
        )

        val text = buildAnnotatedString {
            append("Hello ")
            withStyle(tagStyle){
                append("Lan Tan")
            }
        }

        Text(text = text)
    }

}